package com.examples.savestate;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity {
	private EditText editText;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        editText = (EditText) findViewById(R.id.editText);

        if (savedInstanceState != null) {
        	// We have some state to load
        	String text = savedInstanceState.getString("EditTextValue");
        	editText.setText(text);
        }
        
        final Intent intent = new Intent(this, SecondActivity.class);
		
        Button button = (Button) findViewById(R.id.button);
        button.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				startActivity(intent);
			}
		});
    }
    
    @Override
    public void onPause() {
    	super.onPause();
    }
    
    @Override
    public void onDestroy() {
    	super.onDestroy();
    }
    
    @Override
    public void onSaveInstanceState(Bundle bundle) {
    	bundle.putString("EditTextValue", editText.getText().toString());
    	
    	super.onSaveInstanceState(bundle);
    }
}